package com.keming.dao;

import com.keming.pojo.FriendLink;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface FriendLinkDao {
    //查询友链管理列表
    @Select("select * from myblog.t_friend order by t_friend.create_time desc")
    List<FriendLink> listFriendLink();

    //新增友链
    @Insert("insert into myblog.t_friend (blogname,blogaddress,pictureaddress,create_time) " +
            "values (#{blogname},#{blogaddress},#{pictureaddress},#{createTime})")
    int saveFriendLink(FriendLink friendLink);

    //根据网址查询友链
    @Select("select * from myblog.t_friend f where f.blogaddress = #{blogaddress}")
    FriendLink getFriendLinkByBlogaddress(String blogaddress);

    //根据id查询友链
    @Select("select * from myblog.t_friend f where f.id = #{id}")
    FriendLink getFriendLink(Long id);

    //编辑修改友链
    @Select("update myblog.t_friend set blogname = #{blogname}, blogaddress = #{blogaddress}, pictureaddress = #{pictureaddress} where id = #{id};")
    int updateFriendLink(FriendLink friendLink);

    //删除友链
    @Delete("delete from myblog.t_friend where id = #{id}")
    void deleteFriendLink(Long id);
}
